package com.api.oa.controller;


import com.api.oa.model.entity.YQAssessment;
import com.api.oa.services.YQAssessmentService;
import com.api.shopapi.controller.BaseController;
import com.api.shopapi.entity.MyResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/yq/yQAssessment")
public class YQAssessmentController extends BaseController {

    @Autowired
    private YQAssessmentService iYQAssessmentService;

    @RequestMapping(value = "/add", method = RequestMethod.POST)
    public MyResult Add(@RequestBody YQAssessment entity) {
        try {
            return iYQAssessmentService.add(entity) == 1 ? success(entity) : failed("操作失败");
        } catch (Exception e) {
            return anomalous(getExceptionMsg(e));
        }

    }

    /**
     * 机构评估
     * @param entity
     * @return
     */
    @RequestMapping(value = "/saveByIns", method = RequestMethod.POST)
    public MyResult saveByIns(@RequestBody YQAssessment entity) {
        try {
            return iYQAssessmentService.saveByIns(entity) != null ? success(entity) : failed("操作失败");
        } catch (Exception e) {
            return anomalous(getExceptionMsg(e));
        }

    }

    @RequestMapping(value = "/submit/{id}", method = RequestMethod.GET)
    public MyResult submitIns(@PathVariable String id) {
        try {
            return  iYQAssessmentService.submit(id) == 1 ? success("提交成功!"):failed("操作失败");
        } catch (Exception e) {
            return anomalous(getExceptionMsg(e));
        }

    }
    @RequestMapping(value = "/submit/gov/{id}", method = RequestMethod.GET)
    public MyResult submitGov(@PathVariable String id) {
        try {
            return  iYQAssessmentService.submitGov(id) == 1 ? success("提交成功!"):failed("操作失败");
        } catch (Exception e) {
            return anomalous(getExceptionMsg(e));
        }

    }

    /**
     * 政府复评测
     * @param entity
     * @return
     */
    @RequestMapping(value = "/saveByGov", method = RequestMethod.POST)
    public MyResult saveByGov(@RequestBody YQAssessment entity) {
        try {
            return success(iYQAssessmentService.saveByGov(entity) );
        } catch (Exception e) {
            return anomalous(getExceptionMsg(e));
        }

    }


    @RequestMapping(value = "/remove/{id}", method = RequestMethod.POST)
    public MyResult remove(@PathVariable Long id) {
        try {
            iYQAssessmentService.remove(id);
            return success("删除成功!");
        } catch (Exception e) {
            return anomalous(getExceptionMsg(e));
        }

    }


    @RequestMapping(value = "/update", method = RequestMethod.POST)
    public MyResult update(@RequestBody YQAssessment entity) {
        try {
            return iYQAssessmentService.update(entity) == 1 ? success("操作成功") : failed("操作失败");
        } catch (Exception e) {
            return anomalous(getExceptionMsg(e));
        }

    }


    @RequestMapping(value = "/list", method = RequestMethod.GET)
    public MyResult list(@RequestParam(defaultValue = "1") Integer pageIndex, @RequestParam(defaultValue = "20") Integer pageSize, @RequestParam(required = false) String insCode) {
        try {
            return success(iYQAssessmentService.list(insCode, pageIndex, pageSize));
        } catch (Exception e) {
            return anomalous(getExceptionMsg(e));
        }
    }


    @RequestMapping(value = "/one/{id}", method = RequestMethod.GET)
    public MyResult one(@PathVariable String id) {
        try {
            return success( iYQAssessmentService.one(id));
        } catch (Exception e) {
            return anomalous(getExceptionMsg(e));
        }
    }


}
